<!-- 分类字典 -->
<template>
  <div class="app-container">
    <!-- 搜索聊天记录   -->
    <div class="search-container">
      <el-form ref="queryFormRef" :model="queryParams" :inline="true">
        <el-form-item prop="ip" label="ip">
          <el-input
            v-model="queryParams.ip"
            placeholder="ip"
            clearable
            @keyup.enter="handleQuery"
          />
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="handleQuery">
            <i-ep-search />
            搜索
          </el-button>
          <el-button @click="handleResetQuery">
            <i-ep-refresh />
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
    <!-- ip黑名单   -->
    <el-card shadow="never">
      <el-table
        v-loading="loading"
        :data="pageData"
        highlight-current-row
        border
      >
        <el-table-column label="ID" prop="id" />
        <el-table-column label="ip" prop="ip" />
        <el-table-column label="客服ID" prop="kefuId" />
        <el-table-column label="客服名称" prop="kefuName" />
        <el-table-column label="创建时间" prop="createAt" />
        <el-table-column label="操作" fixed="right" align="left">
          <template #default="scope">
            <el-button
              type="danger"
              link
              size="small"
              @click.stop="handleDelete(scope.row)"
            >
              <i-ep-delete />移除黑名单
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-if="total > 0"
        v-model:total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="handleQuery"
      />
    </el-card>
  </div>
</template>
<script setup lang="js">
defineOptions({
  name: "IpBlack",
  inherititems: false,
});
import { deleteIp, getPage } from "@/api/ipblack";

const queryFormRef = ref(ElForm);

const loading = ref(false);
const total = ref(0);

const queryParams = reactive({
  pageNum: 1,
  pageSize: 10,
  ip: "",
});

// 聊天记录表格数据
const pageData = ref();

/** 查询 */
function handleQuery() {
  loading.value = true;
  getPage(queryParams)
    .then((data) => {
      pageData.value = data.list;
      total.value = data.count;
    })
    .finally(() => {
      loading.value = false;
    });
}

function handleDelete(row) {
  loading.value = true;
  let d = { ip: row.ip };
  deleteIp(d)
    .then((data) => {
      handleQuery();
    })
    .finally(() => {
      loading.value = false;
    });
}

/** 重置查询 */
function handleResetQuery() {
  queryFormRef.value.resetFields();
  queryParams.pageNum = 1;
  handleQuery();
}

onMounted(() => {
  handleQuery();
});
</script>

<style scoped lang="scss"></style>
